package com.zqsign.core.key.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zqsign.core.key.bean.KeyInfo;
import com.zqsign.core.key.dao.KeyPairDao;
import com.zqsign.core.key.pojo.KeyPairInfo;
import com.zqsign.core.key.service.KeyPairService;

/**
* @ClassName 	: KeyPairServiceImpl 
* @Description 	: 
*
* @Company 		: zqsign
* @author 		: wx 
* @date 		: 2018年2月28日 上午11:43:18 
*/
@Service
public class KeyPairServiceImpl implements KeyPairService {

	@Autowired
	private KeyPairDao keyPairDao;
	
	@Override
	public KeyInfo saveKeyInfo(KeyPairInfo keyPairInfo) {
		KeyInfo keyInfo = new KeyInfo();
		keyInfo.setCreateDate(new Date());
		keyInfo.setZqUserId(keyPairInfo.getZqUserId());
		keyInfo.setOrderNum("keypair"+UUID.randomUUID().toString().replaceAll("-", ""));
		keyInfo.setPublicKey(keyPairInfo.getPublicKey());
		keyInfo.setPrivateKey(keyPairInfo.getPrivateKey());
		keyPairDao.insert(keyInfo);
		return keyInfo;
	}

	@Override
	public KeyInfo getKeyInfo(String orderNum) {
		Map<String,Object> condMap = new HashMap<>();
		condMap.put("orderNum", orderNum);
		return keyPairDao.selectOne(condMap);
	}
	
}
